package com.jenkins.test.proxy.gov.business;

import com.alibaba.fastjson.JSONObject;
import com.jenkins.test.proxy.gov.constant.GovStandardSigmoid;
import com.jenkins.test.proxy.gov.constant.RequestType;
import com.jenkins.test.proxy.gov.dto.GovRequest;
import com.jenkins.test.stream.ExpressCondition;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @version V1.0.0
 * @ClassName: {@link DefaultGovEntranceInitialization}
 * @Description: DefaultGovEntranceInitialization 入口
 * @author: Lanzhou
 * @date: 2022/1/22 9:19
 * @Copyright:2020 All rights reserved.
 */
@Service
public class DefaultGovEntranceInitialization implements GovEntranceInitialization {

    /**
     * 企业信息配置
     */
    private Map<GovStandardSigmoid, Object> enterprises = new HashMap<>();

    /**
     * 初始化数据
     *
     * @param sigmoid 函标
     * @param request 请求
     */
    @Override
    public void initialize(GovStandardSigmoid sigmoid, GovRequest request) {
        // 设置请求类型
        RequestType requestType = sigmoid.getReqType();
        ExpressCondition.condition(null == requestType).except("未知协议, 请检查后再试");
        request.setRequestType(requestType);
        request.setBody(JSONObject.toJSONString(request));
        Object config = enterprises.get(sigmoid);
        if (null != config) {
            // TODO 从配置信息里面拿过来

            return;
        }
        // TODO 根据企业编码查询数据库, 获取对应的连接然后设置进Request中

        // TODO 还需要将当前的信息读取进缓存里面

    }

    public Map<GovStandardSigmoid, Object> getEnterprises() {
        return enterprises;
    }

    public void setEnterprises(Map<GovStandardSigmoid, Object> enterprises) {
        this.enterprises = enterprises;
    }
}
